With Command Line support you can send an unlimited number of parameters to your
compiled applications (even to already running apps with a single instance option
enabled).
Look at included cmdline.mbd example.
Simply compile that project and run it with some command line parameters.
Rules for passing command line parameters to MMB exe:
All parameters passed to MMB application are stored (as a string!) in a predefined string array called CmdLineParam$[n] where n is a number between 0 and the number of passed parameters.
CmdLineParam$[0] contains number of passed parameters and the rest of CmdLineParam$[1..n] holds the cmd line parameters. With this you can easily enumerate the parameters passed to exe and then process them.
If you pass some numbers to your app and you want to use them as number (i.e. not as string returned by CmdLineParam$[n]) you will have to convert the string to number (by VAL predefined function).
EXAMPLES:
If you run MMB exe with 3 parameters the
CmdLineParam$[n]
will appear like this:
myprogram.exe param1 param2 param3
CmdLineParam$[0]=>3
**number of passed parameters
CmdLineParam$[1]=>param1
**first parameter
CmdLineParam$[2]=>param2
**second parameter
CmdLineParam$[3]=>param3
**third parameter
Or if you run your exe with two parameters, but one
of them is separated by space...
myprogram.exe param1 "param21
param22"
CmdLineParam$[0]=>2
**number of passed parameters
CmdLineParam$[1]=>param1
**first parameter
CmdLineParam$[2]=>param21
param22**second parameter
Here is a complete (but almost useless) example of parsing command line parameters passed to any MMB application.
EXAMPLE:
Insert this code to MouseUp event of any
active object (e.g. button), compile app and start it with some parameters.
This will show you the parameters in Message box.
**
CmdLineParam$[0] holds number of passed cmd line parameters
n=VAL(CmdLineParam$[0])
**
if number of parameters is > 0 then...
If
(n>0)
Then
** This loop simply
enumerate the passed parameters
For
i=1
To
n
**
..and show the obtained parameters in message box (or do anything you want)
Message("Command
line parameter:","CmdLineParam$[i]")
Next
i
End
However, the above (rather manual) command line processing would be useless without an automated way of processing the passed parameters. If you want to automatically process the command line parameters on time when they arrive to MMB application, just create a new Script object with label CBK_CMDLINE (preferably on Master Page/Layer) and insert your cmd line processing code into this Script object. Each time you will start MMB application with that CBK and with some command line parameters, this CBK_CMDLINE will be invoked and then you can process the passed command line parameters.
With this special script object you can not only process
the command line parameters passed to newly started application, but you can
also process some new parameters to an already running application with
one instance enabled. For example, if the application is already running and
you want to pass some new cmdline parameters to this application, simply call
the application exe once again with your new cmd line parameters.
NOTE!
The dark side of this new command line support (but from our point of view
a big plus ;) is the fact that mmb apps no longer automatically process the
audio/video command line parameters like in previous MMB versions. In other words, if you want to
pass the MP3/OGG file to your app and then play it, you will have to make it play
via new CBK_CMDLINE script. Previously, MMB automatically started known file
formats, like mp3, ogg or avi.
The only file format, which is still loaded if you pass
it to mmb application is MBD project file. If you pass a MBD file as the
first parameter of MMB application, it will be automatically loaded in the application's
main window. If you want to avoid this automatic starting of MBD files, and
process the project files by yourself, then pass the path to MBD file in the
second application parameter (instead of first parameter):
in short, instead of running your application with these
parameters...
myprogram.exe "PathToProject.mbd" "AnyParameter"
run it with these...
myprogram.exe "AnyParameter"
"PathToProject.mbd"
HINT! With command line support you can now create windows Screen Savers including the settings dialog. For an example screensaver.mbd or rlt4.mbd example. Just compile these projects with scr file extension (instead of exe) and add them to Windows folder. Then install them via Display Properties dialog (Screen Saver tab).